﻿<template>
  <div class="xuanKe-container">
    <el-card class="full-table" shadow="hover" style="margin-top: 8px">
      <el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
				row-key="id"
				border="">
        <el-table-column label="操作" width="140" align="center" show-overflow-tooltip="" v-if="auth('myxuanke:page')">
          <template #default="scope">
            <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditXuanKe(scope.row)" v-auth="'myxuanke:edit'" > 选课 </el-button>
            <!-- v-if="!scope.row.isYuxuan && scope.row.xuankeActive" -->
            <!-- <span v-if="scope.row.isYuxuan">预选学生禁止选课</span> -->
            <!-- <span v-if="!scope.row.xuankeActive">未开启选课，选课开始时间{{scope.row.startTime}},选课结束时间{{scope.row.endTime}}</span> -->
            
          </template>
        </el-table-column>
        <el-table-column prop="studentId" label="学生" width="80" show-overflow-tooltip="">
          <template #default="scope">
            <span>{{scope.row.studentIdName}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="kechengId" label="课程" width="250" show-overflow-tooltip="">
          <template #default="scope">
            <span>{{scope.row.kechengIdName}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="isYuxuan" label="是否预选" width="120" show-overflow-tooltip="">
          <template #default="scope">
            <el-tag v-if="scope.row.isYuxuan"> 是 </el-tag>
            <el-tag type="danger" v-else> 否 </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="xuankeTaskId" label="选课任务" width="200" show-overflow-tooltip="">
          <template #default="scope">
            <span>{{scope.row.xuankeTaskIdName}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="banjiId" label="班级" width="120" show-overflow-tooltip="">
          <template #default="scope">
            <span>{{scope.row.banjiIdName}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="jiaoxueBanId" label="教学班" width="120" show-overflow-tooltip="">
          <template #default="scope">
            <span>{{scope.row.jiaoxueBanIdName}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="studentId" label="学号" width="120" show-overflow-tooltip="">
          <template #default="scope">
            <span>{{scope.row.studentIdXh}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="chengji" label="成绩" width="140" show-overflow-tooltip="" />
        <el-table-column prop="remark" label="备注" width="140" show-overflow-tooltip="" />
      </el-table>
      <el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100, 200, 500]"
				small=""
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
	/>
  <editDialog
        ref="editDialogRef"
        :title="editXuanKeTitle"
        @reloadTable="handleQuery"
      />
    </el-card>
  </div>
</template>

<script lang="ts" setup="" name="xuanKe">
  import { ref } from "vue";
  import { ElMessageBox, ElMessage } from "element-plus";
  import { auth } from '/@/utils/authFunction';
  import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  import { formatDate } from '/@/utils/formatTime';

  import editDialog from '/@/views/main/myxuanke/component/editDialog.vue'
  
  import { pageMyXuanke } from '/@/api/main/myXuanke';

  const showAdvanceQueryUI = ref(false);
  const printDialogRef = ref();
  const editDialogRef = ref();
  const loading = ref(false);
  const tableData = ref<any>([]);
  const queryParams = ref<any>({});
  const tableParams = ref({
    page: 1,
    pageSize: 10,
    total: 0,
  });

  const printXuanKeTitle = ref("");
  const editXuanKeTitle = ref("");
 
    // 打开编辑页面
  const openEditXuanKe = (row: any) => {
    editXuanKeTitle.value = '我要选课';
    editDialogRef.value.openDialog(row);
  };

  // 查询操作
  const handleQuery = async () => {
    loading.value = true;
    var res = await pageMyXuanke(Object.assign(queryParams.value, tableParams.value));
    tableData.value = res.data.result?.items ?? [];
    tableParams.value.total = res.data.result?.total;
    loading.value = false;
  };

  // 改变页面容量
  const handleSizeChange = (val: number) => {
    tableParams.value.pageSize = val;
    handleQuery();
  };

  // 改变页码序号
  const handleCurrentChange = (val: number) => {
    tableParams.value.page = val;
    handleQuery();
  };
  
  handleQuery();
</script>
<style scoped>
:deep(.el-ipnut),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>

